// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) fieldsfirst 
// Source File Name:   Result.java

package com.csc.contact.checkbill.utiltools.page;

import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.Date;
import java.util.Hashtable;

public class Result
    implements Serializable
{

    private Object result[][];
    private int rowNumber;
    private int colNumber;
    private int totalRow;
    private int beginRow;
    private Hashtable colNames;

    public Result()
    {
        result = null;
        rowNumber = -1;
        colNumber = -1;
        totalRow = -1;
        beginRow = 1;
        colNames = null;
    }

    public Result(Object rs[][], Hashtable h)
    {
        result = null;
        rowNumber = -1;
        colNumber = -1;
        totalRow = -1;
        beginRow = 1;
        colNames = null;
        colNames = h;
        result = rs;
        if(rs == null)
        {
            rowNumber = 0;
            colNumber = 0;
            totalRow = 0;
        } else
        {
            rowNumber = result.length;
            colNumber = result[0].length;
            totalRow = result.length;
        }
    }

    public Result(Object rs[][], int totalRowNumber, Hashtable h)
    {
        result = null;
        rowNumber = -1;
        colNumber = -1;
        totalRow = -1;
        beginRow = 1;
        colNames = null;
        colNames = h;
        result = rs;
        if(rs == null)
        {
            rowNumber = 0;
            colNumber = 0;
            totalRow = 0;
        } else
        {
            rowNumber = result.length;
            colNumber = result[0].length;
            totalRow = totalRowNumber;
        }
    }

    public int totalNum()
    {
        return totalRow;
    }

    public int rowNum()
    {
        return rowNumber;
    }

    public int colNum()
    {
        return colNumber;
    }

    public Object getObject(int i, int j)
    {
        return result[i][j];
    }

    public Object getObject(int i, String colName)
    {
        int j = ((Integer)colNames.get(colName.toUpperCase())).intValue();
        return getObject(i, j);
    }

    public String getString(int i, int j)
    {
        if(result[i][j] == null)
            return "";
        else
            return (String)result[i][j];
    }

    public String getString(int i, String colName)
    {
        int j = ((Integer)colNames.get(colName.toUpperCase())).intValue();
        return getString(i, j);
    }

    public BigDecimal getBigDecimal(int i, int j)
    {
        if(result[i][j] == null)
            return new BigDecimal(0);
        else
            return new BigDecimal((new StringBuilder()).append(result[i][j]).toString());
    }

    public BigDecimal getBigDecimal(int i, String colName)
    {
        int j = ((Integer)colNames.get(colName.toUpperCase())).intValue();
        return getBigDecimal(i, j);
    }

    public short getShort(int i, int j)
    {
        if(result[i][j] == null)
            return 0;
        else
            return ((BigDecimal)result[i][j]).shortValue();
    }

    public short getShort(int i, String colName)
    {
        int j = ((Integer)colNames.get(colName.toUpperCase())).intValue();
        return getShort(i, j);
    }

    public int getInt(int i, int j)
    {
        if(result[i][j] == null)
            return 0;
        else
            return ((BigDecimal)result[i][j]).intValue();
    }

    public int getInt(int i, String colName)
    {
        int j = ((Integer)colNames.get(colName.toUpperCase())).intValue();
        return getInt(i, j);
    }

    public long getLong(int i, int j)
    {
        if(result[i][j] == null)
            return 0L;
        else
            return ((BigDecimal)result[i][j]).longValue();
    }

    public long getLong(int i, String colName)
    {
        int j = ((Integer)colNames.get(colName.toUpperCase())).intValue();
        return getLong(i, j);
    }

    public float getFloat(int i, int j)
    {
        if(result[i][j] == null)
            return 0.0F;
        else
            return ((BigDecimal)result[i][j]).floatValue();
    }

    public float getFloat(int i, String colName)
    {
        int j = ((Integer)colNames.get(colName.toUpperCase())).intValue();
        return getFloat(i, j);
    }

    public double getDouble(int i, int j)
    {
        if(result[i][j] == null)
            return 0.0D;
        else
            return ((BigDecimal)result[i][j]).doubleValue();
    }

    public double getDouble(int i, String colName)
    {
        int j = ((Integer)colNames.get(colName.toUpperCase())).intValue();
        return getDouble(i, j);
    }

    public Date getDate(int i, int j)
    {
        if(result[i][j] == null)
            return null;
        else
            return (Timestamp)result[i][j];
    }

    public Date getDate(int i, String colName)
    {
        int j = ((Integer)colNames.get(colName.toUpperCase())).intValue();
        return getDate(i, j);
    }

    public Timestamp getTimestamp(int i, int j)
    {
        if(result[i][j] == null)
            return null;
        else
            return (Timestamp)result[i][j];
    }

    public Timestamp getTimestamp(int i, String colName)
    {
        int j = ((Integer)colNames.get(colName.toUpperCase())).intValue();
        return getTimestamp(i, j);
    }

    public void setObject(int i, int j, Object x)
    {
        result[i][j] = x;
    }

    public void setObject(int i, String colName, Object x)
    {
        int j = ((Integer)colNames.get(colName.toUpperCase())).intValue();
        result[i][j] = x;
    }

    public void addColumn(String columnName)
    {
        if(colNumber < 1 || rowNumber < 1 || columnName == null)
            return;
        colNames.put(columnName.toUpperCase(), new Integer(colNumber));
        colNumber++;
        Object newResult[][] = new Object[rowNumber][colNumber];
        for(int i = 0; i < rowNumber; i++)
        {
            for(int j = 0; j < colNumber; j++)
                if(j == colNumber - 1)
                {
                    newResult[i][j] = null;
                } else
                {
                    newResult[i][j] = result[i][j];
                    result[i][j] = null;
                }

        }

        result = newResult;
    }

    public void addColumns(String columnNames[])
    {
        if(colNumber < 1 || rowNumber < 1 || columnNames == null)
            return;
        for(int i = 0; i < columnNames.length; i++)
        {
            colNames.put(columnNames[i].toUpperCase(), new Integer(colNumber));
            colNumber++;
        }

        Object newResult[][] = new Object[rowNumber][colNumber];
        for(int i = 0; i < rowNumber; i++)
        {
            for(int j = 0; j < colNumber; j++)
                if(j >= result[0].length)
                {
                    newResult[i][j] = null;
                } else
                {
                    newResult[i][j] = result[i][j];
                    result[i][j] = null;
                }

        }

        result = newResult;
    }

    public boolean containsCol(String colName)
    {
        return colNames.containsKey(colName);
    }

    public int getBeginRow()
    {
        return beginRow;
    }

    public void setBeginRow(int beginRow)
    {
        this.beginRow = beginRow;
    }
}
